// backend/server.js
const express = require('express');
const cors = require('cors');
const path = require('path');
const articleRoutes = require('./routes/articles');
const testRoutes = require('./routes/test');
const logger = require('./services/logger'); 
const knowledgeRoutes = require('./routes/knowledge'); 

const app = express();
const PORT = 3001;

app.use(cors());
app.use(express.json());

// 【核心新增】配置静态文件服务
// 当浏览器请求 /images/xxx.jpg 时，Express会自动去 public/images/xxx.jpg 文件夹下查找并返回文件
app.use(express.static(path.join(__dirname, 'public')));

// 注册路由
app.use('/api/articles', articleRoutes);
app.use('/api/test', testRoutes);
app.use('/api/knowledge', knowledgeRoutes); 

app.listen(PORT, () => {
logger.info(`后端服务器已启动，正在监听 http://localhost:${PORT}`);
});